package com.example.reidsdemo.interceptors;

import com.alibaba.dubbo.common.utils.StringUtils;
import com.example.reidsdemo.annotation.MyAnnotation;
import org.springframework.stereotype.Component;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class MyInterceptors implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        if (!(handler instanceof HandlerMethod)) {
            return false;
        }
        HandlerMethod handler1 = (HandlerMethod) handler;
        if ((handler1.getMethodAnnotation(MyAnnotation.class)!=null)) {
            System.out.println("本方法有使用MyAnnotation注解");
            return true;
        }
//        String token = request.getHeader("Authorization");
//        if (StringUtils.isNotEmpty(token)) {
//            System.out.println("获取到token");
//        }
//        System.err.println("lalala");
        return false;
    }
}
